home *** CD-ROM | disk | FTP | other *** search
Wrap
Java Source | 2001-06-23 | 13.4 KB | 448 lines
/* ArcanaApp.SpellViewFrame - a means by which to view spell records Written by Scott C. Ziegler for use with Simulcra™. Usage: void clearFields() - clears the fields of data. void displaySpell(Arcana.SpellRecord rec) - displays the param spell in Frame. void setNavigationListener(ActionListener nl) - removes default ActionListener and replaces it with param ActionListener. This listener watches the navigation buttons (Back, Next, PrevLvl, FwdLevel) void setManipulationListener(ActionListener ml) - removes default ActionListener and replaces it with param ActionListener. This listener watches the manipulation buttons (Edit, Delete, Find, New) void setAboutListener(ActionListener al) - removes default ActionListener and replaces it with param ActionListener. Controls about menuItem. void setQuitListener(ActionListener ql)removes default ActionListener and replaces it with param ActionListener. Controls quit behavior. vers. history: 06.22.00 - reached first syntactically stable point. 09.19.00 - decided to overhaul the project using layout managers 10.25.00 - began project to make a functional spell book app Work Needed: - ****** NEED NEED to make AreaOfEffect field presence - *** NEED to make a scroll bar for the description TextArea - finish initMenus() - add JDialog warnings to Delete button and other destructive updates. Work Completed: - made event structure for buttons; - populated the menubar with some menuitems linked to events. - finished debugging errors in display functions. - implemented clearFields and displaySpell */ /* This file and its intellectual contents are considered property of the creator and are to be treated as such with respect to use in other applications. Any use of this software for any purpose whatsoever must have explicit permission from the author of the file. This code is part of an ongoing development process for future possible products, and so is considered private property. Do not use without permission. Author: Scott C. Ziegler <Aslan@Narnia.net> */ package Thoth; import java.awt.*; import java.awt.event.*; import java.util.*; import javax.swing.*; import javax.swing.border.*; import javax.swing.event.*; public class SpellViewFrame extends JFrame { Insets objectInsets = new Insets(2,2,2,2); // Panels JPanel buttonPanel; JPanel recordPanel; // Menus JMenuBar menuBar; JMenu fileMenu; JMenuItem aboutBoxMenuItem; JMenuItem quitMenuItem; JMenu editMenu; JMenuItem undoMenuItem; JMenuItem cutMenuItem; JMenuItem copyMenuItem; JMenuItem pasteMenuItem; JMenu optionsMenu; JMenuItem optionsMenuItem; JMenu someMenu; JMenuItem someMenuItem; // Buttons JButton backButton; JButton nextButton; JButton prevLvlButton; JButton fwdLvlButton; JButton editButton; JButton deleteButton; JButton findButton; JButton newButton; // Labels JLabel nameLabel; JLabel levelLabel; JLabel schoolLabel; JLabel componentsLabel; JLabel rangeLabel; JLabel durationLabel; JLabel castingTimeLabel; JLabel areaOfEffectLabel; JLabel savingThrowLabel; JLabel descriptionLabel; // Text Fields JTextField nameTextField; JTextField levelTextField; JTextField schoolTextField; JTextField componentsTextField; JTextField rangeTextField; JTextField durationTextField; JTextField castingTimeTextField; JTextField areaOfEffectTextField; JTextField savingThrowTextField; JScrollPane descriptionScrollPane; JTextArea descriptionTextArea; ActionListener navigationActionListener; ActionListener manipulationActionListener; ActionListener aboutListener; ActionListener quitListener; // Constructors public SpellViewFrame() { super("Arcana Spell View"); initMenus(); initButtons(); initRecordPanel(); initDescriptionArea(); setJMenuBar(menuBar); Container progFrameContentPane = getContentPane(); progFrameContentPane.add(buttonPanel, BorderLayout.NORTH); progFrameContentPane.add(recordPanel, BorderLayout.CENTER); progFrameContentPane.add(descriptionScrollPane, BorderLayout.SOUTH); setSize(new Dimension(500,600)); //setVisible(true); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { thisWindowClosing(e); } }); } // Selectors // Mutators public void setNavigationListener(ActionListener nl) { backButton.removeActionListener(navigationActionListener); backButton.addActionListener(nl); nextButton.removeActionListener(navigationActionListener); nextButton.addActionListener(nl); fwdLvlButton.removeActionListener(navigationActionListener); fwdLvlButton.addActionListener(nl); prevLvlButton.removeActionListener(navigationActionListener); prevLvlButton.addActionListener(nl); } public void setManipulationListener(ActionListener ml) { editButton.removeActionListener(manipulationActionListener); editButton.addActionListener(ml); deleteButton.removeActionListener(manipulationActionListener); deleteButton.addActionListener(ml); findButton.removeActionListener(manipulationActionListener); findButton.addActionListener(ml); newButton.removeActionListener(manipulationActionListener); newButton.addActionListener(ml); } public void setAboutListener(ActionListener al) { aboutBoxMenuItem.removeActionListener(aboutListener); aboutBoxMenuItem.addActionListener(al); } public void setQuitListener(ActionListener ql) { quitMenuItem.removeActionListener(quitListener); quitMenuItem.addActionListener(ql); } // Methods public void clearFields() { nameTextField.setText(""); levelTextField.setText(""); schoolTextField.setText(""); componentsTextField.setText(""); rangeTextField.setText(""); durationTextField.setText(""); castingTimeTextField.setText(""); areaOfEffectTextField.setText(""); savingThrowTextField.setText(""); descriptionTextArea.setText(""); } public void displaySpell(Arcana.SpellRecord spell) { nameTextField.setText(spell.getName()); levelTextField.setText("" + spell.getLevel()); schoolTextField.setText(spell.getSchool()); switch (spell.getComponents()) { case 0 : componentsTextField.setText("Verbal"); break; case 1 : componentsTextField.setText("Somantic"); break; case 2 : componentsTextField.setText("Material"); break; case 3 : componentsTextField.setText("Verbal, Somantic"); break; case 4 : componentsTextField.setText("Somantic, Material"); break; case 5 : componentsTextField.setText("Verbal, Material"); break; case 6 : componentsTextField.setText("Verbal, Somantic, Material"); break; } rangeTextField.setText(spell.getRange()); durationTextField.setText(spell.getDuration()); castingTimeTextField.setText(spell.getCastingTime()); areaOfEffectTextField.setText(spell.getAreaOfEffect()); savingThrowTextField.setText(spell.getSavingThrow()); descriptionTextArea.setText(spell.getEffect().getDescription()); } private void initMenus() { menuBar = new JMenuBar(); menuBar.setBorder(new BevelBorder(BevelBorder.RAISED)); fileMenu = new JMenu("File"); fileMenu.setMnemonic('F'); aboutBoxMenuItem = new JMenuItem("About…"); fileMenu.add(aboutBoxMenuItem); aboutListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { System.out.println("About!"); } }; aboutBoxMenuItem.addActionListener(aboutListener); quitMenuItem = new JMenuItem("Quit"); fileMenu.add(quitMenuItem); quitListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { //System.exit(0); System.out.println("Quit!"); } }; quitMenuItem.addActionListener(quitListener); editMenu = new JMenu("Edit"); undoMenuItem = new JMenuItem("Undo"); editMenu.add(undoMenuItem); cutMenuItem = new JMenuItem("Cut"); editMenu.add(cutMenuItem); copyMenuItem = new JMenuItem("Copy"); editMenu.add(copyMenuItem); pasteMenuItem = new JMenuItem("Paste"); editMenu.add(pasteMenuItem); optionsMenu = new JMenu("Options"); optionsMenuItem = new JMenuItem("Options…"); optionsMenu.add(optionsMenuItem); someMenu = new JMenu("Something"); someMenuItem = new JMenuItem("Something…"); menuBar.add(fileMenu); menuBar.add(editMenu); menuBar.add(optionsMenu); menuBar.add(someMenu); } private void initButtons() { // this needs to be moved to the app side navigationActionListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { String com = ae.getActionCommand(); if (com.compareTo("Back") == 0) { } else if (com.compareTo("Next") == 0) { } else if (com.compareTo("PrevLvl") == 0) { } else if (com.compareTo("FwdLvl") == 0) { } } }; // this needs to be moved to the app side manipulationActionListener = new ActionListener() { public void actionPerformed(ActionEvent ae) { String com = ae.getActionCommand(); if (com.compareTo("Edit") == 0) { } else if (com.compareTo("Delete") == 0) { } else if (com.compareTo("Find") == 0) { } else if (com.compareTo("New") == 0) { } } }; backButton = new JButton("Back"); backButton.addActionListener(navigationActionListener); nextButton = new JButton("Next"); nextButton.addActionListener(navigationActionListener); prevLvlButton = new JButton("PrevLvl"); prevLvlButton.addActionListener(navigationActionListener); fwdLvlButton = new JButton("FwdLvl"); fwdLvlButton.addActionListener(navigationActionListener); editButton = new JButton("Edit"); editButton.addActionListener(manipulationActionListener); deleteButton = new JButton("Delete"); deleteButton.addActionListener(manipulationActionListener); findButton = new JButton("Find"); findButton.addActionListener(manipulationActionListener); newButton = new JButton("New"); newButton.addActionListener(manipulationActionListener); buttonPanel = new JPanel(); buttonPanel.setLayout(new GridLayout(2,4,5,5)); buttonPanel.add(backButton); buttonPanel.add(nextButton); buttonPanel.add(editButton); buttonPanel.add(deleteButton); buttonPanel.add(prevLvlButton); buttonPanel.add(fwdLvlButton); buttonPanel.add(findButton); buttonPanel.add(newButton); } private void initRecordPanel() { recordPanel = new JPanel(); recordPanel.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); nameLabel = new JLabel("Name:"); nameTextField = new JTextField(); levelLabel = new JLabel("Level:"); levelTextField = new JTextField(); schoolLabel = new JLabel("School:"); schoolTextField = new JTextField(); componentsLabel = new JLabel("Components:"); componentsTextField = new JTextField(); rangeLabel = new JLabel("Range:"); rangeTextField = new JTextField(); durationLabel = new JLabel("Duration:"); durationTextField = new JTextField(); castingTimeLabel = new JLabel("Casting Time:"); castingTimeTextField = new JTextField(); areaOfEffectLabel = new JLabel("Area Of Effect:"); areaOfEffectTextField = new JTextField(); savingThrowLabel = new JLabel("Saving Throw:"); savingThrowTextField = new JTextField(); descriptionLabel = new JLabel("Description:"); setGBConstraints(c,0,0,true); recordPanel.add(nameLabel, c); setGBConstraints(c,1,0,false); recordPanel.add(nameTextField, c); setGBConstraints(c,0,1,true); recordPanel.add(levelLabel, c); setGBConstraints(c,1,1,false); recordPanel.add(levelTextField, c); setGBConstraints(c,0,2,true); recordPanel.add(schoolLabel, c); setGBConstraints(c,1,2,false); recordPanel.add(schoolTextField, c); setGBConstraints(c,0,3,true); recordPanel.add(componentsLabel, c); setGBConstraints(c,1,3,false); recordPanel.add(componentsTextField, c); setGBConstraints(c,0,4,true); recordPanel.add(rangeLabel, c); setGBConstraints(c,1,4,false); recordPanel.add(rangeTextField, c); setGBConstraints(c,0,5,true); recordPanel.add(durationLabel, c); setGBConstraints(c,1,5,false); recordPanel.add(durationTextField, c); setGBConstraints(c,0,6,true); recordPanel.add(castingTimeLabel, c); setGBConstraints(c,1,6,false); recordPanel.add(castingTimeTextField, c); setGBConstraints(c,0,7,true); recordPanel.add(savingThrowLabel, c); setGBConstraints(c,1,7,false); recordPanel.add(savingThrowTextField, c); setGBConstraints(c,0,8,true); recordPanel.add(areaOfEffectLabel, c); setGBConstraints(c,1,8,false); recordPanel.add(areaOfEffectTextField, c); setGBConstraints(c,0,9,true); recordPanel.add(descriptionLabel, c); } private void setGBConstraints(GridBagConstraints gbc, int x, int y, boolean lbl_field) { gbc.gridx = x; gbc.gridy = y; gbc.gridheight = 1; gbc.gridwidth = 1; gbc.weightx = (lbl_field?20:80); gbc.weighty = 11; gbc.fill = (lbl_field?GridBagConstraints.NONE:GridBagConstraints.BOTH); gbc.anchor = (lbl_field?GridBagConstraints.WEST:GridBagConstraints.CENTER); gbc.insets = objectInsets; } private void initDescriptionArea() { descriptionScrollPane = new JScrollPane(); descriptionTextArea = new JTextArea(); descriptionTextArea.setRows(15); descriptionTextArea.setLineWrap(true); descriptionTextArea.setWrapStyleWord(true); descriptionScrollPane.getViewport().add(descriptionTextArea); // sizing? } void thisWindowClosing(java.awt.event.WindowEvent e) { setVisible(false); // dispose(); // System.exit(0); } // Selectors }